﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：S_WORDS实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class S_WORDS
    {
        private decimal m_dec_belongid;

        private decimal m_dec_id;

        private decimal m_dec_isactive;

        private decimal m_dec_sortid;

        private decimal m_dec_wordsid;

        private string m_str_wordscontent;

        private string m_str_wordsremark;

        private string m_str_wordsvalue;

        /// <summary>
        ///     自增量ID
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        ///     词语编号
        /// </summary>
        public decimal WORDSID
        {
            get { return m_dec_wordsid; }
            set { m_dec_wordsid = value; }
        }

        /// <summary>
        ///     词语内容
        /// </summary>
        public string WORDSCONTENT
        {
            get { return m_str_wordscontent; }
            set { m_str_wordscontent = value; }
        }

        /// <summary>
        ///     词语值
        /// </summary>
        public string WORDSVALUE
        {
            get { return m_str_wordsvalue; }
            set { m_str_wordsvalue = value; }
        }

        /// <summary>
        ///     词语备注
        /// </summary>
        public string WORDSREMARK
        {
            get { return m_str_wordsremark; }
            set { m_str_wordsremark = value; }
        }

        /// <summary>
        ///     隶属词语编号
        /// </summary>
        public decimal BELONGID
        {
            get { return m_dec_belongid; }
            set { m_dec_belongid = value; }
        }

        /// <summary>
        ///     排序编号
        /// </summary>
        public decimal SORTID
        {
            get { return m_dec_sortid; }
            set { m_dec_sortid = value; }
        }

        /// <summary>
        ///     是否激活
        /// </summary>
        public decimal ISACTIVE
        {
            get { return m_dec_isactive; }
            set { m_dec_isactive = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class S_WORDSProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public S_WORDSProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据S_WORDS实体添加或者修改S_WORDS信息
        /// </summary>
        public bool InsertOrUpdate(S_WORDS S_WORDS, OracleTransaction Transaction)
        {
            if (S_WORDS.ID == 0)
                InsertS_WORD(S_WORDS, Transaction);
            else
                UpdateS_WORD(S_WORDS, Transaction);
            return S_WORDS.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据S_WORDS实体添加或修改S_WORDS信息
        /// </summary>
        public bool InsertOrUpdate(S_WORDS S_WORDS)
        {
            return InsertOrUpdate(S_WORDS, null);
        }


        /// <summary>
        ///     根据S_WORDS主键删除S_WORDS信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteS_WORD(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelS_WORD";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据S_WORDS主键删除S_WORDS信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteS_WORD(decimal ID)
        {
            return DeleteS_WORD(ID, null);
        }

        /// <summary>
        ///     根据条件删除S_WORDS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteS_WORDsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelS_WORDsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除S_WORDS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteS_WORDsDynamic(string WhereClause)
        {
            return DeleteS_WORDsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据S_WORDS主键选择S_WORDS信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>S_WORDS信息</returns>
        public S_WORDS SelectS_WORD(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelS_WORD";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var S_WORDS = PopulateS_WORDS(rd);
                rd.Close();
                return S_WORDS;
            }
            return null;
        }

        /// <summary>
        ///     根据S_WORDS主键选择S_WORDS信息
        /// </summary>
        /// <returns>S_WORDS信息</returns>
        public S_WORDS SelectS_WORD(decimal ID)
        {
            return SelectS_WORD(ID, null);
        }

        /// <summary>
        ///     选择所有S_WORDS信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有S_WORDS信息</returns>
        public DataTable SelectS_WORDsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelS_WORDsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有S_WORDS信息
        /// </summary>
        /// <returns>所有S_WORDS信息</returns>
        public DataTable SelectS_WORDsAll()
        {
            return SelectS_WORDsAll(null);
        }

        /// <summary>
        ///     根据条件选择S_WORDS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>S_WORDS信息</returns>
        public DataTable SelectS_WORDsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelS_WORDsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择S_WORDS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>S_WORDS信息</returns>
        public DataTable SelectS_WORDsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectS_WORDsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择S_WORDS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>S_WORDS信息</returns>
        public DataTable SelectS_WORDsDynamic(string WhereClause, string OrderByExpression, int PageIndex, int PageSize,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelS_WORDsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择S_WORDS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>S_WORDS信息</returns>
        public DataTable SelectS_WORDsDynamic(string WhereClause, string OrderByExpression, int PageIndex, int PageSize)
        {
            return SelectS_WORDsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新S_WORDS字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateS_WORDsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdS_WORDDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新S_WORDS字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateS_WORDsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateS_WORDsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertS_WORD(S_WORDS S_WORDS, OracleTransaction Transaction)
        {
            var spName = "CS_InsS_WORD";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = S_WORDS.WORDSID;
            storedParams[1].Value = S_WORDS.WORDSCONTENT;
            storedParams[2].Value = S_WORDS.WORDSVALUE;
            storedParams[3].Value = S_WORDS.WORDSREMARK;
            storedParams[4].Value = S_WORDS.BELONGID;
            storedParams[5].Value = S_WORDS.SORTID;
            storedParams[6].Value = S_WORDS.ISACTIVE;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            S_WORDS.ID = Convert.ToInt32(storedParams[7].Value);
            return result;
        }

        private bool UpdateS_WORD(S_WORDS S_WORDS, OracleTransaction Transaction)
        {
            var spName = "CS_UpdS_WORD";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = S_WORDS.WORDSID;
            storedParams[1].Value = S_WORDS.WORDSCONTENT;
            storedParams[2].Value = S_WORDS.WORDSVALUE;
            storedParams[3].Value = S_WORDS.WORDSREMARK;
            storedParams[4].Value = S_WORDS.BELONGID;
            storedParams[5].Value = S_WORDS.SORTID;
            storedParams[6].Value = S_WORDS.ISACTIVE;
            storedParams[7].Value = S_WORDS.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private S_WORDS PopulateS_WORDS(IDataReader dr)
        {
            var S_WORDS = new S_WORDS();
            S_WORDS.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            S_WORDS.WORDSID = dr["WORDSID"] == DBNull.Value ? 0 : (decimal) dr["WORDSID"];
            S_WORDS.WORDSCONTENT = dr["WORDSCONTENT"] == DBNull.Value ? "" : (string) dr["WORDSCONTENT"];
            S_WORDS.WORDSVALUE = dr["WORDSVALUE"] == DBNull.Value ? "" : (string) dr["WORDSVALUE"];
            S_WORDS.WORDSREMARK = dr["WORDSREMARK"] == DBNull.Value ? null : (string) dr["WORDSREMARK"];
            S_WORDS.BELONGID = dr["BELONGID"] == DBNull.Value ? 0 : (decimal) dr["BELONGID"];
            S_WORDS.SORTID = dr["SORTID"] == DBNull.Value ? 0 : (decimal) dr["SORTID"];
            S_WORDS.ISACTIVE = dr["ISACTIVE"] == DBNull.Value ? 0 : (decimal) dr["ISACTIVE"];
            return S_WORDS;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion